package zxq.rollcall.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import zxq.rollcall.course.entity.SystemCourseTableEntity;
import zxq.rollcall.course.entity.SystemTeacherSignTableEntity;
import zxq.rollcall.course.mapper.SystemTeacherSignTableDao;
import zxq.rollcall.course.service.MPSystemTeacherSignTableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 老师签到记录得表 服务实现类
 * </p>
 *
 * @author Yanghu
 * @since 2020-01-22
 */
@Service
public class SystemTeacherSignTableServiceDiy extends ServiceImpl<SystemTeacherSignTableDao, SystemTeacherSignTableEntity> implements MPSystemTeacherSignTableService {

    @Override
    public Integer createTeacherSign(Integer course_id) {
        SystemTeacherSignTableEntity teacherSignTableEntity = new SystemTeacherSignTableEntity();
        teacherSignTableEntity.setCourseId(course_id);
        teacherSignTableEntity.setSignDay(getSignDay());
        boolean rst = save(teacherSignTableEntity);
        if(!rst) {
            return  null;
        }
        return teacherSignTableEntity.getId();
    }

    @Override
    public Integer queryNewTeacherId(Integer course_id) {

        return getBaseMapper().queryNewestTeacherId(course_id);
    }


    @Override
    public String getSignDay() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String signDay = df.format(new Date());
        return signDay;
    }


}
